#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int f[30][N];
int n;
string s;
int main()
{
	cin >> n >> s;
	s = " " + s;
	for (int i = n; i >= 1; i--) {
		for (int k = 1; k <= 26; k++) {
			f[k][i] = f[k][i + 1];
		}
		int x = s[i] - 'a' + 1;
		f[x][i]++;
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		int x = s[i] - 'a' + 1;
		for (int k = 1; k <= 26; k++) {
			if (x != k) {
				LL res = f[k][i + 1];
				ans += (res - 1) * res / 2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}